import requests
import execjs

# publicKey 请求
cookiesPublic = {
    '__jsluid_s': 'a59162ba5aab9e4dbafd94292fe5bc48',
    'SUNWAY-ESCM-COOKIE': '2295206a-8d60-4cfc-89a5-66168eb2a078',
    'JSESSIONID': 'EC3EBF03E35C3C7AA9F4D7933EAB0BE0',
}

headersPublic = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    # 'Content-Length': '0',
    # 'Cookie': '__jsluid_s=a59162ba5aab9e4dbafd94292fe5bc48; SUNWAY-ESCM-COOKIE=2295206a-8d60-4cfc-89a5-66168eb2a078; JSESSIONID=EC3EBF03E35C3C7AA9F4D7933EAB0BE0',
    'Origin': 'https://ec.minmetals.com.cn',
    'Pragma': 'no-cache',
    'Referer': 'https://ec.minmetals.com.cn/open/home/purchase-info',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0',
    'sec-ch-ua': '"Chromium";v="130", "Microsoft Edge";v="130", "Not?A_Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

responsePublic = requests.post('https://ec.minmetals.com.cn/open/homepage/public', cookies=cookiesPublic, headers=headersPublic)

key = responsePublic.text
# page 请求
cookies = {
    '__jsluid_s': 'a59162ba5aab9e4dbafd94292fe5bc48',
    'SUNWAY-ESCM-COOKIE': '2295206a-8d60-4cfc-89a5-66168eb2a078',
    'JSESSIONID': '3161B090DAFD00E0F9AA549EA29C3157',
}

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Type': 'application/json',
    # 'Cookie': '__jsluid_s=a59162ba5aab9e4dbafd94292fe5bc48; SUNWAY-ESCM-COOKIE=2295206a-8d60-4cfc-89a5-66168eb2a078; JSESSIONID=3161B090DAFD00E0F9AA549EA29C3157',
    'Origin': 'https://ec.minmetals.com.cn',
    'Pragma': 'no-cache',
    'Referer': 'https://ec.minmetals.com.cn/open/home/purchase-info',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0',
    'sec-ch-ua': '"Chromium";v="130", "Microsoft Edge";v="130", "Not?A_Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

enc_params = execjs.compile(open("./wukuang.js").read()).call("enc_page", 2, key)
print("enc_params:::", enc_params)

json_data = {
    'param': enc_params,
}

response = requests.post(
    'https://ec.minmetals.com.cn/open/homepage/zbs/by-lx-page',
    cookies=cookies,
    headers=headers,
    json=json_data,
)
print(response.text)
# Note: json_data will not be serialized by requests
# exactly as it was in the original request.
#data = '{"param":"ocTTkKJOPG4QDzciTBL6CmS7qkN7pCL4ENra9lbFPgwCW4ZGTSxToFCPu8GWFvoZVI//p9tMOdKZXWhmOlQLbJhwV4shXQ3RYigE0Da3H7CaGvbZZG7il2Zer9Tlh/OnMxDlMMDdHxcq/Yp4Y/b2NcIzwT/gDKMEi67fPvU6o9U7/ZnSFZdu3DctCPUpSYGk0jFfaG0LGuoyGl3MweWxEF3d5qBg6EGvPD4OUAnxqkv5S8VAnKBWtVJ+Ss31l/7EwLCtfxUCwbUOfit3jfj9W0aXSvkBt6bbw79qygXRT6lVzv7PVtcvqIySuWjqcGgq2N6i/Xn22BdNqZlPVDjYf4tOkzGp0gw8dPyOa+I+Yvw2sUpX/rzScj6sEfZmnwQ7bmv7mbKy7r+sJy8IJfMdcOOlyumGSq8a66UtL9pW1+EwxsW+m9M7rukSS+eodzZ7srPKfmcjwzYC4qMgDlW4Z82NMUhfFVQA8KEnRuW5OZZFfS7Q8eTqPrkxtClTalWAfdGyVbDYqt/9hc36RFZdRtVywUT8CICA4QxB6UWlCuFWnZR8djWCVp28gGEwfyNEPUUNofo6lT2/ZUYij7z2i4pgkjew8iMIgcZFXpCjGj2r+4QVCF5TFo9PVfY752+CxXBguutD4An23rHAmt6SBLALXbtGTkmMVuEE6C7TLto="}'
#response = requests.post('https://ec.minmetals.com.cn/open/homepage/zbs/by-lx-page', cookies=cookies, headers=headers, data=data)